﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的评测</title>
    <script type="text/javascript" src="libs/jquery-3.6.0.min.js"></script>
    <script type="text/javascript" src="libs/layer.js"></script>
    <style type="text/css">
        .base_info {
          width: 400px;
          display: block;
          line-height: 40px;
          font-size: 16px;
            color: #444444;
            font-family: 'Microsoft YaHei';
            text-align: left;
        }
        .layui-layer-dialog {
          min-width: 220px;
        }
    </style>
</head>
<body style="text-align:center;background:#f8f8f8;margin:0px;">
    <div style="width:1200px;margin-left:auto;margin-right:auto;background:#ffffff;box-shadow: 0px 0px 15px #888888;">
        <div style="height:174px;width:1200px;background:url('libs/kpitop.png') no-repeat;text-align:left">
            <div id="pagename" style="font-family:'Microsoft YaHei';font-size:26px;top:10px;left:100px;position:relative;color:#ffffff;">陕西工业职业技术学院处科级岗位干部网络测评系统</div>
            <div id="pageName_assesstype" style="font-family:'Microsoft YaHei';font-size:22px;top:40px;left:100px;position:relative;color:#ffffff;">测评项目名称</div>
            <div id="pageName_assessdate" style="font-family:'Microsoft YaHei';font-size:18px;top:55px;left:100px;position:relative;color:#ffffff;">测评日期：2021年12月15日</div>

            <button  style="float: right;margin-top:-20px;margin-right: 30px;padding:10px 20px;position: relative" onclick="closethis()">退出</button>
        </div>
        <div style="width:1200px;background:#ffffff;height:200px;vertical-align:top;border-bottom:1px solid #999999;">

            <div style="width:200px;display:inline-block;height:100%;vertical-align: top;">
                <img id="userimage" src="libs/kpiphoto.png" style="margin:15%;height:70%" />
            </div>
            <div style="width:400px;display:inline-block;height:100%;padding:25px 30px 5px 30px;vertical-align: top;">
                <span class="base_info base_info_nickname">姓名：正在获取……</span>
                <span class="base_info base_info_dept">所在部门：正在获取……</span>
                <span class="base_info base_info_role">职务：正在获取……</span>
                <span class="base_info base_info_username">员工编号：正在获取……</span>
            </div>
            <div style="width:450px;display:inline-block;height:80%;vertical-align: top;text-align:left;padding:30px 20px 10px 20px;">
                <span style="line-height:40px;font-size:20px;color:#444444;font-family:'Microsoft YaHei';text-align:left;">分数: </span>
                <input type="text" style="width:150px;border-radius:3px;border:1px solid #666666;height:30px;font-size:20px;text-align:right;" id="assessScore"/>
                <button style="height:34px;border:1px solid #666666;padding:5px 30px;border-radius:3px;font-family:'Microsoft YaHei';vertical-align:middle;margin-top:-8px;" onclick="saveAssess()">保存</button>
                <br /><br />
                <span style="line-height:25px;font-size:15px;color:#888888;font-family:'Microsoft YaHei';text-align:left;margin-top:20px;">
                    评分参考：优秀（100分~90分）； 良好（89分~80分）；合格（79分~70分）；不合格（69分~0分）；
                </span>
            </div>
        </div>
        <div style="width:1200px;background:#ffffff;height:1000px;vertical-align:top;">
            <iframe id="iframeShuzhi" style="width:100%;height:100%;overflow-y:scroll;border:0px;" src="demo.pdf"></iframe>
        </div>
    </div>
    <div id="beassesseds" style="display:none;padding:20px 20px;text-align: left"></div>
    <script>
    var serverType="http://"+window.location.hostname+":4321";
      $(function(){

        //看看缓存里面有没有用户名和用户编号，如果有就自动登录，没有的话输入登录
        var savednickname=localStorage.getItem("nickname");
        var savedusername=localStorage.getItem("username");
        if(savednickname==null||savednickname==undefined||savedusername==null||savedusername==undefined) {
          layer.prompt({
              title: '请填写您的名字，并确认'
            },
            function(nickname) {
              layer.prompt({
                  title: '请填写您的员工编号，并确认'
                },
                function(username) {
                  //layer.msg('演示完毕！您的口令：'+ nickname +' 您最后写下了：'+ username);
                  //验证用户的名字、员工编号、传入的tempcode
                  accessCode(nickname, username);
                });
            });
        }else{
          accessCode(savednickname, savedusername);
        }
      });

      function accessCode(nickname,username){
        var tempcode=getQueryString("tempcode");
        $.getJSON(serverType+"/kpi/verifyUser",{
            tempcode:tempcode,
            nickname:nickname,
            username:username
        },function(result){
            if(result.code==200){
                if(parseInt(result.data.code)==0){
                    //加载被考评人信息
                  localStorage.setItem("nickname",nickname);
                  localStorage.setItem("username",username);
                    loadKpiBaseInfo();
                    layer.closeAll();
                }else{
                    layer.msg('验证用户失败。');
                    //window.close();
                }
            }else{
                layer.msg('与服务器连接失败，验证用户失败。');
                //window.close();
            }
        })
      }

      function loadKpiBaseInfo(){
        var tempcode=getQueryString("tempcode");
        $.getJSON(serverType+"/kpi/getKpiBaseInfo",{
          tempcode:tempcode
        },function(result){
            fillKpiBaseInfo(result.data);
            //生成左侧菜单
            makeLeftNav(result.data.beassessed);
        })
      }

      function makeLeftNav(beassesseds){
        var str="";
        for(var i=0;i<beassesseds.length;i++){
          var abeassesseds=beassesseds[i];
          str+="<a href='"+abeassesseds.path+"' style='display: block;padding:5px 20px' >"+abeassesseds.nick_name+"</a>";
        }
        $("#beassesseds").html(str);
          layer.open({
            title:"所有待测评人员",
            closeBtn:0,
            offset:["0px","0px"],
            area:["220px","700px"],
            type:1,
            content:$("#beassesseds"),
            shade:false
          });
      }

      function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
      }

      function fillKpiBaseInfo(result){
        $("#pageName_assesstype").text(result.assesstype);
        $("#pageName_assessdate").text(result.assessdate);
        $(".base_info_nickname").text("被测评人姓名："+result.nickname);
        $(".base_info_dept").text("所在部门："+result.user.dept.deptName);
        if(result.user.roles.length>0){
          $(".base_info_role").text("职务："+result.user.roles[0].roleName);
        }else{
          $(".base_info_role").text("职务：暂未设置");
        }
        $(".base_info_username").text("员工编号："+result.user.userName);
        if(result.userimg!="") {
          $("#userimage").attr('src', result.userimg);
        }
        $("#iframeShuzhi").attr('src',serverType+result.userreport);
      }

        function saveAssess(){
            var assessScore=$("#assessScore").val();
            var tempcode=getQueryString("tempcode");
             $.getJSON(serverType+"/kpi/saveAssessScore",{
                  assessScore:assessScore,
                  tempcode:tempcode
                },function(result){
                    if(result.data.code=="0"){
                        layer.msg('打分数据已保存。请点击关闭退出页面', {
                            time:0, //20s后自动关闭
                            btn: [ '知道了'],
                            btn1: function(index){
                                window.close();
                            }
                        });
                    }else{
                        layer.msg('数据保存错误。', {
                            time:0,
                            btn: [ '知道了'],
                            btn1:function(){
                              layer.closeAll();
                            }
                        });
                    }
                })
        }

        function  closethis(){
          localStorage.removeItem("nickname");
          localStorage.removeItem("username");
          window.close();
        }
    </script>
</body>
</html>
